package com.qst.mapper;

import com.github.pagehelper.Page;
import com.qst.domain.Book;
import org.apache.ibatis.annotations.*;

@Mapper
public interface BookMapper {

    @Select("select * from book where book_status != 3 order by book_uploadtime desc")
    @Results(id = "bookMap",value = {
            @Result(id = true,column = "book_id",property = "id"),
            @Result(column = "book_name",property = "name"),
            @Result(column = "book_isbn",property = "isbn"),
            @Result(column = "book_press",property = "press"),
            @Result(column = "book_author",property = "author"),
            @Result(column = "book_pagination",property = "pagination"),
            @Result(column = "book_price",property = "price"),
            @Result(column = "book_uploadtime",property = "uploadTime"),
            @Result(column = "book_status",property = "status"),
            @Result(column = "book_borrower",property = "borrower"),
            @Result(column = "book_borrowtime",property = "borrowTime"),
            @Result(column = "book_returntime",property = "returnTime")
    })
    Page<Book> selectNewBooks();


    @Select("select * from book where book_id = #{id}")
    @ResultMap("bookMap")   // 封装结果集
    Book findById(String id);

    // 修改图书信息
    Integer editBook(Book book);
    // 查询图书
    Page<Book> searchBooks(Book book);

    //新增图书
    Integer addBook(Book book);

    // 管理员的当前借阅
    Page<Book> selectBorrowed(Book book);
    // 普通用户的当前借阅
    Page<Book> selectMyBorrowed(Book book);
}
